package org.springblade.pm.config;

import org.springblade.core.boot.file.BladeFileUtil;
import org.springblade.core.tool.constant.SystemConstant;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.io.File;

/**
 * @author LK
 * @version 1.0.0
 * @Title: WebMvcConfiguration.java
 * @Description: TODO    静态资源访问配置类
 * @date 2020/4/20 11:32
 */
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

	/**
	 * 添加静态资源文件，外部可以直接访问地址
	 *
	 * @param registry
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		System.out.println(BladeFileUtil.formatUrl(SystemConstant.me().getUploadRealPath() + File.separator + "image" + File.separator));
		String upDir = BladeFileUtil.formatUrl(System.getProperty("user.dir") + "/work/blade/upload/");
		//如下配置则能可以访问下面的文件
		if (upDir.contains(":")) {
			upDir = upDir.replace(":", ":/");
		}
		System.out.println("上传文件路径为：" + upDir);
		registry.addResourceHandler("/**").addResourceLocations("file:" + upDir);
	}
}
